package com.suke.czx.modules.supplier.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.suke.czx.common.utils.CodeConstant;
import com.suke.czx.common.utils.R;
import com.suke.czx.modules.contact.service.ContactService;
import com.suke.czx.modules.supplier.entity.Supplier;
import com.suke.czx.modules.supplier.mapper.SupplierMapper;
import com.suke.czx.modules.supplier.service.SupplierService;
import lombok.AllArgsConstructor;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

/**
 * 应用模块名称: 供应商
 * 代码描述: 供应商业务层
 * copyright: AUZAR ALL RIGHTS RESERVED
 * company: AUZAR
 *
 * @author: 颜米晨
 * @date: 2021/08/31 15:31:27
 */
@Service
@AllArgsConstructor
public class SupplierServiceImpl extends ServiceImpl<SupplierMapper, Supplier> implements SupplierService {

    private final SupplierMapper supplierMapper;

    private final ContactService contactService;

    /**
     * 删除客户
     * @param customerId 客户编码
     * @param userId 操作者编码
     * @return VO
     */
    @Override
    @Transactional(rollbackFor = Exception.class)
    public R updateDelSupplier(Long customerId, Long userId) {
        // 删除供应商
        supplierMapper.updateDelSupplier(customerId, userId);
        // 删除供应商对应的所有联系人
        contactService.updateDelContactByRelation(CodeConstant.CONTACT_TYPE_SUPPLIER, customerId, userId);
        return R.ok();
    }

}
